<?php
class Inflector
{
    /**
     * Gets a reference to the Inflector object instance
     * 
     * @access public
     * @return object
     */
    public function &getInstance() 
    {
		static $instance = NULL;

		if (!$instance) {
			$instance = new Inflector;
		}

		return $instance;
	}

    /**
     * Returns the given lower_case_and_underscored_word as a CamelCased word.
     * 
     * @param string $lowerCaseAndUnderscoredWord 
     * @static
     * @access public
     * @return string 
     */
    public static function camelize($lowerCaseAndUnderscoredWord) 
    {
		$_this = Inflector::getInstance();
		//if (!($result = $_this->_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) {
			$result = str_replace(' ', '', Inflector::humanize($lowerCaseAndUnderscoredWord));
			//$_this->_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord, $result);
		//}
		return $result;
	}

    /**
     * Returns the given camelCasedWord as an underscored_word.
     *
     * @param string $camelCasedWord Camel-cased word to be "underscorized"
     * @return string Underscore-syntaxed version of the $camelCasedWord
     * @access public
     * @static
     */
	function underscore($camelCasedWord) {
		$_this =& Inflector::getInstance();
		//if (!($result = $_this->_cache(__FUNCTION__, $camelCasedWord))) {
			$result = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord));
			//$_this->_cache(__FUNCTION__, $camelCasedWord, $result);
		//}
		return $result;
	}

    /**
     * Returns the given underscored_word_group as a Human Readable Word Group.
     * (Underscores are replaced by spaces and capitalized following words.)
     * 
     * @param string $lowerCaseAndUnderscoredWord 
     * @static
     * @access public
     * @return string 
     */
    public static function humanize($lowerCaseAndUnderscoredWord) 
    {
		$_this =& Inflector::getInstance();
		//if (!($result = $_this->_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) {
			$result = ucwords(str_replace('_', ' ', $lowerCaseAndUnderscoredWord));
			//$_this->_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord, $result);
		//}
		return $result;
	}


}
